/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.action;

import com.myapp.dao.DaoDocumento;
import com.myapp.dao.DaoFacade;
import com.myapp.model.Documento;
import com.myapp.util.ManipuladoraArquivo;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author elio
 */
public class ExcluirDocumentoAction extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";
    private static final String FAILURE = "failure";
    
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        DaoFacade dao = DaoDocumento.getInstance();
       int id = Integer.parseInt(request.getParameter("id")); 
       try{
        Documento d = (Documento) dao.carregarUm(id, Documento.class);
        dao.excluir(d);
        ManipuladoraArquivo.removerArquivo(String.valueOf(id));   
        return mapping.findForward(SUCCESS);
        }catch (Exception e){
        return mapping.findForward(FAILURE);
    }
    }
}
